@extends('public.dashboard_base')
@section('title', '添加企业认证')

@section('content')
    @php
        $user =auth('admin')->user();
    @endphp
    <div class="control_panel_content">
        <div class="navBreadcrumb">
            <ul>
                <li>账户管理</li>
                <li>我的认证</li>
                <li>添加企业认证</li>
            </ul>
        </div>
        <div class="panel">
            <div class="sub_nav_container">
                <ul class="clearfix">
                    <li><a href="/account/auth/company">企业认证</a></li>
                    <li class="active"><a href="/account/auth/company/add">添加企业认证</a></li>
                </ul>
            </div>
            <div class="panel_body">
                <form id="form" enctype="multipart/form-data" method="post">
                    {{csrf_field()}}
                    <ul class="form_group">
                        <li><span class="form_label">企业名称</span> <input type="text" name="name"></li>
                        <li><span class="form_label">证件类型</span>
                            <select name="type" style="width:280px">
                                <option value="10">组织机构代码证书</option>
                                <option value="11">工商营业执照</option>
                                <option value="12">统一社会信用代码证书</option>
                                <option value="13">部队代号</option>
                                <option value="14">军队单位对外有偿服务许可证</option>
                                <option value="15">事业单位法人证书</option>
                                <option value="16">外国企业常驻代表机构登记证</option>
                                <option value="17">社会团体法人登记证书</option>
                                <option value="18">宗教活动场所登记证</option>
                                <option value="19">民办非企业单位登记证书</option>
                                <option value="20">基金会法人登记证书</option>
                                <option value="21">律师事务所执业许可证</option>
                                <option value="22">外国在华文化中心登记证</option>
                                <option value="23">外国政府旅游部门常驻代表机构批准登记证</option>
                                <option value="24">司法鉴定许可证</option>
                                <option value="25">境外机构证件</option>
                                <option value="26">社会服务机构登记证书</option>
                                <option value="27">民办学校办学许可证</option>
                                <option value="28">医疗机构执业许可证</option>
                                <option value="29">公证机构执业证</option>
                                <option value="30">北京市外国驻华使馆人员子女学校办学许可证</option>
                                <option value="9">其他</option>
                            </select>
                        </li>
                        <li><span class="form_label">证件号码</span> <input type="text" name="number"></li>
                        <li>
                            <span class="form_label">证件图片</span>
                            <div class="upload_img" style="background:  no-repeat center 20px;background-size:70%">
                                <div><i class="iconfont iconxiangji"></i></div>
                                <p>上传证件正面</p>
                                <input class="txt" type="hidden" name="image1" id="image1" value="">
                                <img id="img" src="" style="display: none;"><font style="color: #cc3333">请上传JPG格式的图片</font>
                                <input class="txt" type="file" name="file" value="" onchange="uploadimg()">

                                <!--  <input type="file" name="companyFile" id="companyFile">-->
                            </div>
                        </li>
                        <li>
                            <span class="form_label">&nbsp;</span>
                            <input type="submit" class="btn btn_primary" id="add_auth" value="添加">
                        </li>
                    </ul>
                </form>
            </div>
        </div>
    </div>
@endsection
@section('script')
    <script>
        $(function () {
            var link=  $("#account-certification");
            link.parent().parent().parent().addClass("active");
            link.parent().addClass("active");


            //提交
            $("#form").validate({
                rules: {
                    name: {
                        required: true,
                    },
                    type: {
                        required: true,
                    },
                    number: {
                        required: true,
                    },
                },
                onkeyup: false,
                focusCleanup: true,
                success: "valid",
                submitHandler: function (form) {
                    if ($("#image1").attr('value')===''){
                        layer.msg('请先上传证件',{icon:2,time:2000});
                        return false;
                    }
                    $(form).ajaxSubmit({
                        type: 'post',
                        success: function (data) {
                            if (data.msg === 'success') {
                                layer.msg('成功!', {icon: 1, time: 1500}, function () {
                                    window.location = '/account/auth/company';
                                })
                            } else {
                                layer.msg(data.data.error, {icon: 2, time: 2000,});
                            }
                        },
                        error: function (XmlHttpRequest, textStatus, errorThrown) {
                            layer.msg(XmlHttpRequest.responseJSON.data, {icon: 2, time: 2000}, function () {
                            });
                        }
                    });
                }
            });
        });
        //上传图片
        function uploadimg() {
            $('#form').ajaxSubmit({
                type: "POST",
                url: '/upload',
                dataType: 'json',
                success: function (data) {
                    if (data.code === 200) {
                        $('#image1').val(data.data.url);
                        $('#img').show();
                        $('#img').attr("src","/"+data.data.url);
                        $('#upload-file').remove();
                    } else {
                        layer.msg('上传失败!', {icon: 2, time: 2000,});
                    }
                }
            });
        }
    </script>
    @endsection
